<?php
/**
 * Copyright (c) 2006, PORTALIER Julien
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @package      Feather PHP
 * @subpackage   Database
 * @copyright    Copyright (c) 2006, Julien PORTALIER
 * @link         http://feather.portalier.com
 * @license      http://www.opensource.org/licenses/mit-license.php The MIT License
 */

require APP.'config'.DS.'database.php';
require FEATHER.'database'.DS.'drivers'.DS.'db_base.php';

class Database
{
	private static $configs = null;
	private static $dbo = array();
	
	static function get($ds)
	{
		if (!isset(self::$dbo[$ds]))
		{
			// config
			if (is_null(self::$configs)) self::$configs = new DatabaseConfig;
			$conf = self::$configs->$ds;
			
			// driver
			$dbClass = 'db_'.$conf['driver'];
			require_once FEATHER.'database'.DS.'drivers'.DS."$dbClass.php";
			$db = new $dbClass(&$conf);
			
			// active record?
			/*
			if ($conf['active_record'])
			{
				require_once FEATHER.'database'.DS.'active_record.php';
				self::$dbo[$ds] = new ActiveRecord($db);
			}
			else {
				self::$dbo[$ds] = $db;
			}
			*/
			self::$dbo[$ds] = $db;
		}
		return self::$dbo[$ds];
	}
}
?>